package com.baizhi.aop;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

/**
 * redis集群配置类
 */
@Configuration
public class RedisConfig {

    @Value("${redis.nodes}")
    private String nodes;

    @Bean
    public JedisCluster cluster() //集群
    {
        Set<HostAndPort> set = new HashSet<HostAndPort>();
        String[] arrayNodes =nodes.split(",");
        for(String s:arrayNodes)
        {
            String host = s.split(":")[0];
            Integer port = Integer.parseInt(s.split(":")[1]);
            set.add(new HostAndPort(host,port) );
        }
        JedisCluster jedisCluster = new JedisCluster(set);
        return  jedisCluster;

    }


}
